package demo.hello;

public class Why {
	public static void main(String[] args) {
		Linked link=new Linked();
		link.set(new Node(1));
		link.set(new Node(2));
		link.set(new Node(3));
		link.set(new Node(4));
		link.set(new Node(5));
		link.set(new Node(6));
		link.head.next.next=null;
//		System.out.println(link.get().num);
//		System.out.println(link.get().num);
		System.out.println(link.get().num);
		System.out.println(link.get().num);
		System.out.println(link.get().num);
		System.out.println(link.get().num);
	}
}

class Linked {
	Node head = null;

	public void set(Node node) {
		if (head == null)
			head = node;
		else {
			node.next = head;
			head = node;
		}
	}

	public Node get() {
		if (head == null)
			return new Node(-1);
		else {
			Node ret = new Node(head.num);
			head = head.next;
			return ret;
		}
	}
}

class Node {
	int num;
	Node next = null;

	public Node(int n) {
		num=n;
	}
}
